Linq to SQL DynamicInvoke(System.Object[])' has no supported translation to SQL.

Posted by ewwwyn on Stack Overflow See other posts from Stack Overflow or by ewwwyn
Published on 2010-04-28T13:29:28Z Indexed on 2010/04/28 13:33 UTC
Read the original article Hit count: 541

I have a class, Users.

Users has a UserId property.

I have a method that looks something like this:

static IQueryable<User> FilterById(this IQueryable<User> p, Func<int, bool> sel)
{
   return p.Where(m => sel(m));
}

Inevitably, when I call the function:

var users = Users.FilterById(m => m > 10);

I get the following exception:

Method 'System.Object DynamicInvoke(System.Object[])' has no supported translation to SQL.

Is there any solution to this problem? How far down the rabbit hole of Expression.KillMeAndMyFamily() might I have to go?

To clarify why I'm doing this: I'm using T4 templates to autogenerate a simple repository and a system of pipes. Within the pipes, instead of writing:

new UserPipe().Where(m => m.UserId > 10 && m.UserName.Contains("oo") && m.LastName == "Wee");

I'd like to generate something like:

new UserPipe()
  .UserId(m => m > 10)
  .UserName(m => m.Contains("oo"))
  .LastName("Wee");

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql